<template>
  <svg :class="svgClass" aria-hidden="true" v-on="$listeners">
    <use :xlink:href="iconName"></use>
  </svg>
</template>

<script>
export default {
  name: 'SvgIcon',
  props: {
    type: {
      type: String,
      required: true
    },
    className: {
      type: String,
      default: ''
    }
  },
  computed: {
    iconName() {
      // 这里的iconName要和vue.config.js里面导出的一致
      return '#icon-' + this.type;
    },
    svgClass() {
      if (this.className) {
        return 'svg-icon-' + this.className;
      } else {
        return 'svg-icon';
      }
    }
  }
};
</script>

<style scoped>
.svg-icon {
  vertical-align: -0.15em;
  overflow: hidden;
  width: 1em;
  height: 1em;
  fill: currentColor;
}
</style>
